SystemLogView = Ext.extend(Ext.Panel, {
	searchPanel : null,
	gridPanel : null,
	store : null,
	topbar : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		SystemLogView.superclass.constructor.call(this, {
			id : "SystemLogView",
			title : "系统日志管理",
			iconCls : "menu-systemlog",
			layout : "border",
			autoScroll : true			
		});
	},
	initUIComponents : function() {
		this.initSearchPanel();
		this.initGridPanel();
		this.items = [ this.searchPanel, this.gridPanel ];
	},
	onSearch : function(c) {
		var a = Ext.getCmp("SystemLogSearchForm");
		var b = Ext.getCmp("SystemLogGrid");
		if (a.getForm().isValid()) {
			$search({
				searchPanel : a,
				gridPanel : b
			});
		}
	}	
});
SystemLogView.prototype.initSearchPanel = function() {
	this.searchPanel = new Ext.FormPanel({
		region : "north",
		height : 35,
		frame : false,
		border : false,
		id : "SystemLogSearchForm",
		layout : "hbox",
		layoutConfig : {
			padding : "5",
			align : "middle"
		},
		defaults : {
			xtype : "label",
			border : false,
			margins : {
				top : 0,
				right : 4,
				bottom : 4,
				left : 4
			}
		},
		items : [{
			text : "用户名"
		}, {
			xtype : "textfield",
			name : "Q_username_S_LK",
			width:110
		}, {
			text : "操作时间  从"
		}, {
			xtype : "datefield",
			name : "Q_operationTime_D_GT",
			format : "Y-m-d",
			width:90
		}, {
			text : "至"
		}, {
			xtype : "datefield",
			name : "Q_operationTime_D_LT",
			format : "Y-m-d",
			width:90
		},{
			text : "操作"
		}, {
			xtype : "textfield",
			name : "Q_operation_S_LK"
		},		
		{
			xtype : "button",
			text : "查询",
			iconCls : "search",
			scope : this,
			handler : this.onSearch.createCallback(this)
		},{
			xtype:"button",
			text:"清除",
			iconCls:"reset",
			scope:this,
			handler:SystemLogReset
		} ]
	});
	SystemLogView.prototype.initGridPanel = function() {
		this.toolbar = new Ext.Toolbar({
			height : 30,
			items : []
		});
		if (isGranted("_SystemLogDel")) {
			this.toolbar.add(new Ext.Button({
				iconCls : "btn-delete",
				text : "删除日志",
				handler : function() {
					var h = Ext.getCmp("SystemLogGrid");
					var f = h.getSelectionModel().getSelections();
					if (f.length == 0) {
						Ext.ux.Toast.msg("信息", "请选择要删除的记录！");
						return;
					}
					var j = Array();
					for ( var g = 0; g < f.length; g++) {
						if (f[g].data.id) {
							j.push(f[g].data.id);
						} 
					}
						SystemLogView.remove(j);
				}
			}));
		}
		var b = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : __ctxPath + "/system/listSystemLog.do"
			}),
			reader : new Ext.data.JsonReader({
				root : "result",
				totalProperty : "totalCounts",
				fields : [ 
				"id", "userId","operation","entityName","operationDetail","operationTime"]
			}),
			remoteSort : true
		});
		b.setDefaultSort("operationTime", "desc");
		b.load({
			params : {
				start : 0,
				limit : 25
			}
		});
		var e = new Ext.grid.CheckboxSelectionModel();
		var a = new Ext.grid.ColumnModel(
				{
					columns : [
							e,
							new Ext.grid.RowNumberer(),
							{
								header : "id",
								dataIndex : "id",
								hidden : true
							},
							{
								header : "用户名",
								dataIndex : "userId",
								width : 60
							},							
							{
								header : "操作",
								dataIndex : "operation",
								width : 40
							},
							{
                                header : "操作对象",
                                dataIndex : "entityName",
                                width : 80
                            },
                            {
                                header : "数据内容",
                                dataIndex : "operationDetail",
                                width : 210
                            },
                            {
                                header : "时间",
                                dataIndex : "operationTime",
                                width : 80
                              
                            },
							{
								header : "管理",
								dataIndex : "id",
								sortable : false,
								width : 40,
								renderer : function(j, i, g, m, h) {							
									var k = "";
									if (j) {
										if (isGranted("_SystemLogDel")) {
											k += '<button title="删除" value=" " class="btn-delete" onclick="SystemLogView.remove('
													+ j + ')"></button>';
										}
									}
									return k;
								}
							} ],
					defaults : {
						sortable : true,
						menuDisabled : true,
						width : 100
					}
				});
		this.gridPanel = new Ext.grid.GridPanel({
			id : "SystemLogGrid",
			tbar : this.toolbar,
			store : b,
			region : "center",
			shim : true,
			trackMouseOver : true,
			disableSelection : false,
			loadMask : true,
			cm : a,
			sm : e,
			viewConfig : {
				forceFit : true,
				enableRowBody : false,
				showPreview : false
			},
			bbar : new HT.PagingBar({
				store : b
			})
		});
		
		this.gridPanel.addListener("celldblclick", d);
		var c = this.gridPanel;
		function d(g, f, h) {
			g.getSelectionModel().each(function(j) {
				var id = j.data.id;
				new SystemLogShow({id:id}).show();
			});
		}
	};
};
SystemLogReset=function(){
	var a=Ext.getCmp("SystemLogSearchForm");
	a.getForm().reset();
}
SystemLogView.remove = function(b) {
	var a = Ext.getCmp("SystemLogGrid");
	Ext.Msg.confirm("信息确认", "您确认要删除该记录吗？", function(c) {
		if (c == "yes") {
			Ext.Ajax.request({
				url : __ctxPath + "/system/deleteSystemLog.do",
				params : {
					ids : b
				},
				method : "post",
				success : function() {
					Ext.ux.Toast.msg("信息", "成功删除所选记录！");
					a.getStore().reload({
						params : {
							start : 0,
							limit : 25
						}
					});
				},
				failure : function(c, d) {
					Ext.ux.Toast.msg("操作提示", "操作出错，请联系管理员！");
				}
			});
		}
	});

};